package com.bsfcs.rag.repository;

import com.bsfcs.rag.entity.Task;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TaskRepository extends JpaRepository<Task, String> {
    
    /**
     * 根据项目ID查找所有任务
     * @param projectId 项目ID
     * @return 任务列表
     */
    @Query("SELECT new com.bsfcs.rag.entity.Task(t.id, t.parentId, t.title, t.states, t.priority, " +
            "t.project_stage, t.describe, t.isaccounts, t.billcode, " +
            "t.charger, t.charger_dept_name, t.charger_org_name, t.workprocess, t.estimated_time, " +
            "t.registration_time, t.estimated_day, t.resource_role_name, t.resource_avg_cost, " +
            "t.start_time, t.end_time, t.remaining_time, t.create_time) FROM Task t WHERE t.parentId = :projectId")
    List<Task> findByParentId(@Param("projectId") String projectId);
    
    /**
     * 根据项目ID列表查找所有任务
     * @param projectIds 项目ID列表
     * @return 任务列表
     */
    @Query("SELECT t FROM Task t WHERE t.parentId IN :projectIds")
    List<Task> findByParentIds(@Param("projectIds") List<String> projectIds);
}